<?php

/**
 * AuthController.php
 *
 * Holds abstract class AuthController
 *
 * @package Application
 * @subpackage Controllers
 */

/**
 * AuthController
 *
 * Public page base controller
 *
 * @package Application
 * @subpackage Controllers
 */
abstract class AuthController extends PageController {
	
	/**
	 * Initializes page
	 *
	 * @return AuthController (fluent interface)
	 */
	public function init() {
		parent::init();
		if(false === $this->getAuth()){
			$module = strtolower($this->_module);
			$controller = strtolower(substr($this->_controller,0,strlen($this->_controller) - strlen("Controller")));
			$action = strtolower(substr($this->_action,6));
			$link = "{$module}_{$controller}_{$action}";
			die(header("location: /default/login/index/link/{$link}"));
		}
		
		return $this;
	}
	
	/**
	 * Return true if conditions will Authorize this request, else return false
	 *
	 * When false is returned the page will be redirect to /default/login/index with the current controller, module, action as a call-back link.
	 * When true is returned the page will be displayed normally.
	 *
	 * @return true on Authorized false on non-Authorized
	 */
	protected abstract function getAuth();
}
